package com.project.controller;

import com.framework.core.result.APIListResponse;
import com.project.base.BaseController;
import com.project.biz.CmsUserSearchRecordsBiz;
import com.project.common.model.UserInfo;
import com.project.pojo.model.GetUserSearchContentsModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 搜索记录
 * @Author: zhuchi
 * @CreateDate: 2020/12/9 16:24
 * @Version: 1.0
 */
@Api(value = "CmsUserSearchRecordsController", description = "搜索记录")
@RestController
@RequestMapping("/searchRecords")
@Slf4j
public class CmsUserSearchRecordsController extends BaseController {

    /**
     * 用户搜索记录业务层接口类
     */
    @Autowired
    private CmsUserSearchRecordsBiz searchRecordsBiz;

    /**
     * 获取用户搜索记录
     * @return
     */
    @ApiOperation(value = "获取用户搜索记录")
    @PostMapping(value = "/getUserSearchRecords")
    public APIListResponse<String> getUserSearchRecords(@RequestBody GetUserSearchContentsModel getUserSearchContentsModel){
        List<String> list = new ArrayList<>();
        if (StringUtils.isNotBlank(super.getToken())){
            UserInfo userInfo = super.getLoginUser();
            list = this.searchRecordsBiz.getUserSearchContents(getUserSearchContentsModel, userInfo.getBaseUserId());
        }

        return APIListResponse.success("查询成功", list);
    }

}
